package blackitheima1.ClassTest;

import blackitheima1.Domain.Student;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

//反射获取Constructor对象
public class MyClass2 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
        //创建Class类
        Class aClass = Class.forName("blackitheima1.Domain.Student");
        //调用构造方法
        Constructor constructor = aClass.getDeclaredConstructor(String.class,int.class);
        System.out.println(constructor);

        //暴力反射
        constructor.setAccessible(true);
        Student stu = (Student) constructor.newInstance("张三", 12);
        System.out.println(stu);

    }
}
